<?php

class ShopsController extends Controller
{
	public function filters() {
		return array(
			array('application.filters.isAuthorizedFilter'),
			array('application.filters.accessControlFilter','roles'=>array(Users::ADMIN_ROLE)),
		);
	}

	public function actionList()
	{
		$model = new Shops('search');
		$model->unsetAttributes();
		if(isset($_GET['Shops'])){
			$model->attributes=$_GET['Shops'];
		}
		$this->render('list', array(
			'model'=>$model,
		));
	}

	public function actionAdd($id=null)
	{
		if($id){
			$model = Shops::model()->findByPk($id);
			if($model === null)
				$this->redirect(Yii::app()->createUrl('shops/list'));
		} else {
			$model = new Shops();
		}

		if(isset($_POST['Shops'])){
			$model->attributes = Yii::app()->input->stripClean($_POST['Shops']);
			if($model->save())
				$this->redirect(Yii::app()->createUrl('shops/list'));
		}

		$this->render('add',array('model'=>$model));
	}

	public function actionRemove($id)
	{
		$model = Shops::model()->findByPk($id);
		if($model !== null){
			$model->active = $model->active?0:1;
			$model->save();
		}

		$this->redirect(Yii::app()->createUrl('shops/list'));
	}
}